package coml.dzsw.base.proxy.cglib;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CglibProxy implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        System.out.println("before do business.");
        if (method.getName().equals("doSomething")) {
            args[0] = "This is " + args[0] + ".";
        }
        Object result = methodProxy.invokeSuper(o, args);
        System.out.println("after do business.");
        return result;
    }
}
